#ifndef GAMEWINDOW_HPP
#define GAMEWINDOW_HPP

#include <QWidget>
#include <QDockWidget>
#include <QGridLayout>
#include <QListWidget>
#include <QTextEdit>
#include <QLineEdit>
#include <QPushButton>
#include <QLabel>
#include <QCloseEvent>

#include "gobanview.hpp"
#include "client.hpp"
#include "game.hpp"
#include "mainwindow.hpp"

class MainWindow;
class Client;
class Game;
class GobanView;

class GameWindow : public QMainWindow
{
    Q_OBJECT
public:
    GameWindow(Client * client, Game * game, MainWindow * mainWindow, QWidget * parent = 0);
    ~GameWindow();

    quint8 id() const;
    void heLeft(quint8 playerID);
    void gameDestroyed();
    void someoneSaid(const QString & message);
    Client * client() const;
    void reactMovePlayed(quint8 playerID, quint8 x, quint8 y);
    void setScore(quint8 playerID, qreal newScore);
    void displayBadMove();
    void skipTurn();
    void setEstablishingScore(bool isEstablishingScore);
    void reactGroupKilled(quint8 x, quint8 y);
    void reactGroupSaved(quint8 x, quint8 y);

    void reactGroupsValidated(quint8 playerID);
    void reactToPlayAgain();
    void reactGameover(qreal blackScore, qreal whiteScore);

    Game * game() const;

    bool meToPlay() const;
    bool amIBlack() const;
    bool amIWhite() const;

private:
    Client * _client;
    Game * _game;
    MainWindow * _mainWindow;

    QDockWidget * _dockGoban;
    QDockWidget * _dockPlayers;
    QDockWidget * _dockButtons;
    QDockWidget * _dockScore;
    QDockWidget * _dockChat;

    GobanView * _dockGobanContent;
    QListWidget * _dockPlayersContent;
    QWidget * _dockScoreContent;
    QWidget * _dockChatContent;
    QWidget * _dockButtonsContent;

    QLabel * _gobanTitle;
    QLabel * _playersTitle;
    QLabel * _scoreTitle;
    QLabel * _chatTitle;
    QLabel * _buttonsTitle;

    QGridLayout * _dockScoreLayout;
    QGridLayout * _dockChatLayout;
    QGridLayout * _dockButtonsLayout;

    QLabel * _blackStone;
    QLabel * _blackName;
    QLabel * _blackScore;
    QLabel * _whiteStone;
    QLabel * _whiteName;
    QLabel * _whiteScore;

    QListWidget * _listMessages;
    QLineEdit * _message;
    QPushButton * _send;
    QPushButton * _validate;
    QPushButton * _skip;
    QPushButton * _cancel;

    bool _isFinished;

protected:
    void closeEvent(QCloseEvent * event);

signals:
    void closed(quint8 id);

public slots:
    void reactUpdatePlayer();

private slots:
    void reactSendClicked();
    void reactSkipPressed();
    void reactValidatePressed();
    void reactCancelClicked();
};

#endif // GAMEWINDOW_HPP
